<template>
  <div class="info-panel">
    <div class="info-content">
      <div class="info-item">
        <span class="info-label">荣誉名称：</span>
        <span class="info-value">{{ info.title || '暂无' }}</span>
      </div>
      <div class="info-item">
        <span class="info-label">获奖名次：</span>
        <span class="info-value">{{ info.awardLevel || '暂无' }}</span>
      </div>
      <div class="info-item">
        <span class="info-label">级别：</span>
        <span class="info-value">{{ info.level || '暂无' }}</span>
      </div>
      <div class="info-item">
        <span class="info-label">授予单位：</span>
        <span class="info-value">{{ info.grantingUnit || '暂无' }}</span>
      </div>
      <div class="info-item">
        <span class="info-label">获奖时间：</span>
        <span class="info-value">{{ formatTime(info.awardTime) || '暂无' }}</span>
      </div>
      <div class="info-item">
        <span class="info-label">本人排名：</span>
        <span class="info-value">{{ info.authorRank !== null ? info.authorRank : '暂无' }}</span>
      </div>
      <div class="info-item">
        <span class="info-label">作者信息：</span>
        <span class="info-value">
          {{ info.authorInfo && info.authorInfo.length > 0
            ? info.authorInfo.map(author => author.name || author.id).join('、')
            : '暂无' }}
        </span>
      </div>
      <div class="info-item">
        <span class="info-label">备注信息：</span>
        <span class="info-value">{{ info.remarks || '暂无' }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
// 定义接收的props，与后端实体类字段对应
const props = defineProps({
  info: {
    type: Object,
    default: () => ({})
  }
})

// 时间格式化函数
const formatTime = (timestamp) => {
  if (!timestamp) return null

  try {
    // 判断是否是时间戳（数字或数字字符串）
    const timeValue = typeof timestamp === 'string' && isNaN(timestamp)
        ? new Date(timestamp)
        : new Date(Number(timestamp))

    // 格式化为 YYYY-MM-DD 格式
    const year = timeValue.getFullYear()
    const month = String(timeValue.getMonth() + 1).padStart(2, '0')
    const day = String(timeValue.getDate()).padStart(2, '0')

    return `${year}-${month}-${day}`
  } catch (e) {
    console.error('时间格式化错误:', e)
    return null
  }
}
</script>

<style scoped>
.info-panel {
  height: 100%;
}

.info-content {
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
}

.info-item {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-label {
  font-size: 12px;
  color: #9aa0a6;
  font-weight: 500;
}

.info-value {
  font-size: 13px;
  color: #e8eaed;
  word-break: break-all;
  line-height: 1.4;
}

/* 滚动条样式优化 */
.info-content::-webkit-scrollbar {
  width: 8px;
}

.info-content::-webkit-scrollbar-track {
  background: #323639;
}

.info-content::-webkit-scrollbar-thumb {
  background: #5f6368;
  border-radius: 4px;
}

.info-content::-webkit-scrollbar-thumb:hover {
  background: #80868b;
}
</style>
